package com.design.pattern.factory;

import com.design.pattern.constants.Constants;

/**
 * 工厂模式测试类
 */
public class FactoryTest {
    public static void main(String[] args) {
        //简单工厂模式测试
        simpleFactoryTest();

        //工厂方法模式测试
        factoryMethodTest();
    }

    /**
     * 简单工厂模式测试
     */
    public static void simpleFactoryTest() {
        SimpleFactoryPattern simpleFactory = new SimpleFactoryPattern();
        Car bmw = simpleFactory.createCar(Constants.BMW);
        bmw.drive();

        Car benz = simpleFactory.createCar(Constants.Benz);
        benz.drive();

        Car audi = simpleFactory.createCar(Constants.Audi);
        audi.drive();
    }

    /**
     * 工厂方法模式测试
     */
    public static void factoryMethodTest() {
        //创建奥迪工厂
        FactoryMethodPattern audiFactory = new AudiFactory();
        audiFactory.createCar().drive();

        //宝马工厂
        FactoryMethodPattern bmwFactory = new BmwFactory();
        bmwFactory.createCar().drive();

        //奔驰工厂
        FactoryMethodPattern benzFactory = new BenzFactory();
        benzFactory.createCar().drive();
    }
}
